package com.liugh.service.zhongche.Imp;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.liugh.entity.standard.Department;
import com.liugh.mapper.zhongche.DepartmentMapper;
import com.liugh.service.zhongche.IDepartmentService;
import com.liugh.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Fatao on 2018/11/9 .
 */
@Service
public class DepartmentServiceImpl implements IDepartmentService {


    @Autowired
    private DepartmentMapper departmentMapper;


    /**
     * 增加一个部门 .
     * @param department .
     * @return .
     */
    public Department addDepartment(Department department) {
        return CommonUtil.isDBOpSuccess(departmentMapper.insert(department)) ? department : null;
    }


    /**
     * 删除一个部门 .
     * @param id .
     * @return .
     */
    public int  deleteDepartment(int id) {
        return departmentMapper.deleteById(id);
    }


    /**
     * 更新部门信息 .
     * @param department .
     * @return .
     */
    public Department updateDepartment(Department department) {
        return CommonUtil.isDBOpSuccess(departmentMapper.updateById(department)) ? department : null;
    }


    /**
     * 根据id获取部门 .
     * @param id .
     * @return .
     */
    public Department getDepartmentById(int id) {
        return departmentMapper.selectById(id);
    }


    /**
     * 获取所有的部门 .
     * @param page .
     * @return .
     */
    public Page<Department> getAllDepartment(Page<Department> page) {
        return page.setRecords(departmentMapper.selectPage(page, new EntityWrapper<>()));
    }



}
